package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.RecActualItemEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 接运物品实际明细关联表Provider
 *
 * @author generator
 * @date 2020-07-06 11:20
 */
public class RecActualItemProvider {

    /**
     * 增加RecActualItem
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 11:20
     */
    public String insertRecActualItem(@Param("entity") RecActualItemEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" rec_actual_item ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" rec_id ", " #{entity.recId,jdbcType=INTEGER} ");
                VALUES(" rec_code ", " #{entity.recCode,jdbcType=VARCHAR} ");
                VALUES(" service_item_id ", " #{entity.serviceItemId,jdbcType=INTEGER} ");
                VALUES(" item_price ", " #{entity.itemPrice,jdbcType=DECIMAL} ");
                VALUES(" item_number ", " #{entity.itemNumber,jdbcType=DECIMAL} ");
                VALUES(" item_unit ", " #{entity.itemUnit,jdbcType=VARCHAR} ");
                VALUES(" item_charge ", " #{entity.itemCharge,jdbcType=DECIMAL} ");
                VALUES(" discount_charge ", " #{entity.discountCharge,jdbcType=DECIMAL} ");
                VALUES(" benefit_charge ", " #{entity.benefitCharge,jdbcType=DECIMAL} ");
                VALUES(" reality_charge ", " #{entity.realityCharge,jdbcType=DECIMAL} ");
                VALUES(" charge_time ", " #{entity.chargeTime,jdbcType=TIMESTAMP} ");

                if (entity.getAsUnsettled() != null) {
                    VALUES(" as_unsettled ", " #{entity.asUnsettled,jdbcType=TINYINT} ");
                }


                if (entity.getAsSettled() != null) {
                    VALUES(" as_settled ", " #{entity.asSettled,jdbcType=TINYINT} ");
                }

                VALUES(" charge_settle_id ", " #{entity.chargeSettleId,jdbcType=INTEGER} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" item_name ", " #{entity.itemName,jdbcType=VARCHAR} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改RecActualItem
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 11:20
     */
    public String updateRecActualItem(@Param("entity") RecActualItemEntity entity) {
        return new SQL() {
            {
                UPDATE(" rec_actual_item ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                SET(" rec_code = #{entity.recCode,jdbcType=VARCHAR} ");
                SET(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                SET(" item_price = #{entity.itemPrice,jdbcType=DECIMAL} ");
                SET(" item_number = #{entity.itemNumber,jdbcType=DECIMAL} ");
                SET(" item_unit = #{entity.itemUnit,jdbcType=VARCHAR} ");
                SET(" item_charge = #{entity.itemCharge,jdbcType=DECIMAL} ");
                SET(" discount_charge = #{entity.discountCharge,jdbcType=DECIMAL} ");
                SET(" benefit_charge = #{entity.benefitCharge,jdbcType=DECIMAL} ");
                SET(" reality_charge = #{entity.realityCharge,jdbcType=DECIMAL} ");
                SET(" charge_time = #{entity.chargeTime,jdbcType=TIMESTAMP} ");

                if (entity.getAsUnsettled() != null) {
                    SET(" as_unsettled = #{entity.asUnsettled,jdbcType=TINYINT} ");
                }


                if (entity.getAsSettled() != null) {
                    SET(" as_settled = #{entity.asSettled,jdbcType=TINYINT} ");
                }

                SET(" charge_settle_id = #{entity.chargeSettleId,jdbcType=INTEGER} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" item_name = #{entity.itemName,jdbcType=VARCHAR} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询RecActualItem列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 11:20
     */
    public String listRecActualItem(@Param("entity") RecActualItemEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,rec_id,rec_code,service_item_id,item_price,item_number,item_unit,item_charge,discount_charge,benefit_charge,reality_charge,charge_time,as_unsettled,as_settled,charge_settle_id,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version,item_name ");
                SELECT(builder.toString());
                FROM(" rec_actual_item ");

                if (entity.getRecId() != null) {
                    WHERE(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                }

                if (entity.getRecCode() != null) {
                    WHERE(" rec_code = #{entity.recCode,jdbcType=VARCHAR} ");
                }

                if (entity.getServiceItemId() != null) {
                    WHERE(" service_item_id = #{entity.serviceItemId,jdbcType=INTEGER} ");
                }

                if (entity.getItemPrice() != null) {
                    WHERE(" item_price = #{entity.itemPrice,jdbcType=DECIMAL} ");
                }

                if (entity.getItemNumber() != null) {
                    WHERE(" item_number = #{entity.itemNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getItemUnit() != null) {
                    WHERE(" item_unit = #{entity.itemUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getItemCharge() != null) {
                    WHERE(" item_charge = #{entity.itemCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getDiscountCharge() != null) {
                    WHERE(" discount_charge = #{entity.discountCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getBenefitCharge() != null) {
                    WHERE(" benefit_charge = #{entity.benefitCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getRealityCharge() != null) {
                    WHERE(" reality_charge = #{entity.realityCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getChargeTime() != null) {
                    WHERE(" charge_time = #{entity.chargeTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getAsUnsettled() != null) {
                    WHERE(" as_unsettled = #{entity.asUnsettled,jdbcType=TINYINT} ");
                }

                if (entity.getAsSettled() != null) {
                    WHERE(" as_settled = #{entity.asSettled,jdbcType=TINYINT} ");
                }

                if (entity.getChargeSettleId() != null) {
                    WHERE(" charge_settle_id = #{entity.chargeSettleId,jdbcType=INTEGER} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

                if (entity.getItemName() != null) {
                    WHERE(" item_name = #{entity.itemName,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}